#include "pch.h"
#include "DrawCircle.h"


int DrawCircle::draw(CDC* pDC, int startx, int starty, int endx, int endy, COLORREF color)
{
		int t1 = abs(endx - startx) * abs(endx - startx);
		int t2 = abs(endy - starty) * abs(endy - starty);
		double r = sqrt(double(t1 + t2)) / 2;
		int cx = (startx + endx) / 2;
		int cy = (starty + endy) / 2;
		int x = 0, y = r, F = 3 - 2 * r;
		while (x < y)
		{
			CirPot(cx, cy, x, y, pDC,color);
			if (F < 0)
				F += 4 * x + 6;
			else
			{
				F += 4 * (x - y) + 10;
				y--;
			}
			x++;
		}
		if (x == y)
			CirPot(cx, cy, x, y, pDC, color);
		return 0;
}
void DrawCircle::CirPot(int cx, int cy, int x, int y, CDC* pDC, COLORREF color)
{
	pDC->SetPixel((cx + x), (cy + y), color);
	pDC->SetPixel((cx + y), (cy + x), color);
	pDC->SetPixel((cx + y), (cy - x), color);
	pDC->SetPixel((cx + x), (cy - y), color);
	pDC->SetPixel((cx - x), (cy - y), color);
	pDC->SetPixel((cx - y), (cy - x), color);
	pDC->SetPixel((cx - y), (cy + x), color);
	pDC->SetPixel((cx - x), (cy + y), color);
}